package com.naiterui.ehp.bs.patient.dao.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.naiterui.ehp.bs.patient.dao.IMedicationRemindDao;
import com.naiterui.ehp.bs.patient.domain.MedicationRemind;
import com.naiterui.ehp.bs.patient.repository.IApMedicationRemindRepository;

@Component
public class ApMedicationRemindDaoImpl implements IMedicationRemindDao {

    @Autowired
    private IApMedicationRemindRepository medicationRemindRepository;

    /**
     * 获得患者的用药提醒记录
     *
     * @param patientId
     *
     * @return
     *
     * @Author fanjd
     * @Date 2018年1月10日
     * @see com.naiterui.ehp.bs.patient.dao.IMedicationRemindDao#getMedicationRemind(java.lang.Long)
     * @since 1.0.0
     */
    @Override
    public MedicationRemind getMedicationRemind(Long patientId) {
        return medicationRemindRepository.findFirstByPatientId(patientId);
    }

    /**
     * 根据标签获得否和条件且未过期的用药提醒记录
     *
     * @param labelType
     *
     * @return
     *
     * @Author fanjd
     * @Date 2018年1月10日
     * @since 2.14.0
     */
    @Override
    public List<MedicationRemind> getMedicationRemindList(Integer labelType, Date queryDate) {
        return medicationRemindRepository.getMedicationRemindList(labelType, queryDate);
    }

    @Override
    public void removeMedicationRemind(Long patientId) {
        medicationRemindRepository.deleteByPatientId(patientId);
    }

    @Override
    public MedicationRemind saveOrUpdate(MedicationRemind medicationRemind) {
        return medicationRemindRepository.saveOrUpdate(medicationRemind);
    }
}
